﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Easydp.Models.Entities;
using Easydp.Models;
using System.Data;

namespace Easydp.Controllers
{
    public class TradeController
    {
        TradeManager dal = new TradeManager();


        public bool Insert(TT_Trade obj)
        {
            try
            {
                if (dal.Insert(obj) > 0)
                    return true;
                else
                    return false;
            }
            catch (Exception ex)
            {
               
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// 
        public void Update(TT_Trade model)
        {
            try
            {
                int i = dal.Update(model);
                if (i <= 0)
                    throw new Exception("更新失败");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        /// 
        public TT_Trade GetModel(int orderid)
        {
            return dal.GetModel(orderid);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// 
        public DataSet GetDataset(string Where)
        {
            return dal.GetDadaset(Where);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// [DataObjectMethod(DataObjectMethodType.Select)]
        /// 
        [DataObjectMethod(DataObjectMethodType.Select)]
        public DataSet GetFunds(int AgentID, string OrderNumber, string inDate, string outDate,string tradeType)
       {
           StringBuilder strSql = new StringBuilder();
           strSql.Append("select * from V_TT_Trade_Pan_GetFunds  ");
           strSql.Append(" WHERE AgentID=" + AgentID + " ");
           if (inDate != "yyyy-mm-dd" && inDate != "" && inDate != null)
           {
               strSql.Append(" and  NotifyTime >= '" + inDate + "'");
           }
           if (outDate != "yyyy-mm-dd" && outDate != "" && outDate != null)
           {
               strSql.Append(" and  NotifyTime <= '" + outDate + "'");
           }
           if (OrderNumber != "" && OrderNumber != null)
           {
               strSql.Append(" and  OrderNumber = '" + OrderNumber + "'");
           }
           if (tradeType != "所有")
           {
               strSql.Append(" and  PayType = '" + OrderNumber + "'");
           }
            strSql.Append(" ORDER BY CreateOn");

            try
            {
                return dal.GetFunds(strSql.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
       }




        /// <summary>
        /// 得到列表
        /// </summary>
        /// 
        public List<TT_Trade> Getlist(int TradeID)
        {
            return dal.GetList(TradeID);
        }
    }
}
